Julia: High Performance Programming by Balbaert Ivo & Sengupta Avik & Sherrington Malcolm

Julia: High Performance Programming by Balbaert Ivo & Sengupta Avik & Sherrington Malcolm

Author:Balbaert, Ivo & Sengupta, Avik & Sherrington, Malcolm
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2016-11-28T05:00:00+00:00


An example

Let us look at some code to play the game Bulls and Cows. A computer program moo, written in 1970 at MIT in the PL/I, was among the first Bulls and Cows computer implementation.

It is proven that any number could be solved for up to seven turns and the minimal average game length is 5.21 turns.

The computer enumerates a four digit random number from the digits 1 to 9, without duplication. The player inputs his/her guess and the program should validate the player's guess, reject guesses that are malformed, then print the 'score' in terms of number of bulls and cows.

The score is computed as follows:

One bull is accumulated for each digit in the guess that equals the corresponding digit in the randomly chosen initial number

One cow is accumulated for each digit in the guess that also appears in the randomly chosen number, but in the wrong position

The player wins if the guess is the same as the randomly chosen number, and the program ends

Otherwise the program accepts a new guess, incrementing the number of 'tries'



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.